//app.js
App({
  globalData: {
    openid: '',
    sessionKey: '',
    unionid: '',
    shareuserid: "",
    hastel: false,
    jobList: "",
    workparms: {},
    jobcommitparms: {
      workTypeId: "",
      title: "",
      content: "",
      count: "",
      sex: "ALL",
      workPlace: "",
      address: "",
      detailAddress: "",
      latitude: "",
      longitude: "",
      unit: "",
      cycle: "",
      payment: "",
      benifit: [],
      partDuration: "SHORT_TERM",
      workTime: "",
      workDay: "",
      timeNeed: "",
      minDay: "",
      contact: "",
      tel: "",
      email: "",
      isVip: ""
    },
  },
  onLaunch: function(opt) {
    // session_key 已经失效，需要重新执行登录流程
    const that = this;
    wx.clearStorage() //清除token重新获取
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey,
        getApp().globalData.get("/api/wx/auth", {
          code: res.code
        }).then(res => {
          that.globalData.openid = res.data.openid;
          that.globalData.sessionKey = res.data.sessionKey;
          that.globalData.unionid = res.data.unionid;
          wx.setStorageSync('sessionKey', res.data.sessionKey)
          wx.setStorageSync('openid', res.data.openid)
        })
      }
    })
  },
  onShow(e) {
    if (this.globalData.shareuserid == "") {
      this.globalData.shareuserid = e.query.id;
    }
  },
  hastoken() {
    let token = wx.getStorage("key");
    console.log(token)
    if (token === undefined) {

    }
  }
})